package com.simba.server.commands.impl.record;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;
import com.simba.server.base.CommonUtil;
import com.simba.server.components.data.MachineOps;

public class RecordMachineOpsCmd implements ICommand
{
	public static final String NAME = "RecordMachineOpsCmd";
	private final MachineOps machineOps;
	private final String sql = "insert into tt_machine_ops_info(workerNo,opsType,opsDesc) values(?,?,?);";

	public RecordMachineOpsCmd(MachineOps machineOps)
	{
		this.machineOps = machineOps;
	}

	@Override
	public String getName()
	{
		return RecordMachineOpsCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}

		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);

			dbOperator.setString(1,  CommonUtil.doNullData(this.machineOps.getWorkerNo(), "none"));
			dbOperator.setInt(2,  this.machineOps.getOpsType());
			dbOperator.setString(3,  CommonUtil.doNullData(this.machineOps.getOpsDesc(), "none"));

			int res = dbOperator.executeUpdate();
			if (res > 0)
			{
				ret = true;
			}
			else
			{
				ret = false;
			}
		}
		catch (Exception ex)
		{
			ret = false;
		}

		return ret;
	}

}
